//
//  UIBarButtonItem+Extension.swift
//  CSYMicroBlockSina
//
//  Created by 姚彦兆 on 15/11/19.
//  Copyright © 2015年 姚彦兆. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(imageName : String , target : AnyObject? , actionName : String?){
    
        let btn = UIButton(type: UIButtonType.Custom)
        
//        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
//        
//        btn.setBackgroundImage(UIImage(named: "\(imageName) + _highlighted"), forState: UIControlState.Highlighted)
        
        btn.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        btn.setImage(UIImage(named: "\(imageName) + _highlighted"), forState: UIControlState.Highlighted)
        
        if let targetObj = target , selectorAction = actionName {
        
            btn.addTarget(targetObj, action: Selector(selectorAction), forControlEvents: UIControlEvents.TouchUpInside)
        
        }
        
        btn.sizeToFit()
        
        self.init(customView: btn)
        
    }

}
